function createWebSocket() {
  return new Promise((resolve, reject) => {
    // 创建WebSocket对象, 连接服务器
    const socket = new WebSocket('ws://localhost:8899')
    // 绑定连接成功的监听, 监听回调中将socket对象传递给promise的成功value
    socket.onopen = () => {
      resolve(socket)
    }
    // 绑定错误的监听, 监听回调中将error对象传递给promise失败的reason
    socket.onerror = (error) => {
      reject(error)
    }

  })
}

export default createWebSocket